﻿// =================================================================
//  Copyright (c) "David R. Guindo", Software architect
//  
//  This code is released under the terms of the Apache License, Version 2.0,
//  http://www.apache.org/licenses/LICENSE-2.0
//  
//  THIS CODE AND INFORMATION ARE PROVIDED WITHOUT WARRANTIES,
//  WITHOUT LIMITING COMMERCIAL OR PARTICULAR USE.
// =================================================================

namespace ScreenManagerDemo
{
   using System.Windows;
   using System.Windows.Controls;

   internal static class NavigationView
   {
      internal static void CloseView(UserControl view)
      {
         if (view == null || view.Parent == null)
         {
            return;
         }

         if (view.Parent is Decorator)
         {
            (view.Parent as Decorator).Child = null;
         }
         else
         {
            var panel = view.Parent as Panel;
            if (panel != null)
            {
               panel.Children.Remove(view);
            }
         }
      }

      internal static void ShowView(UserControl view, FrameworkElement container)
      {
         if (container == null)
         {
            return;
         }

         if (container is Decorator)
         {
            (container as Decorator).Child = view;
         }
         else
         {
            var panel = container as Panel;
            if (panel != null)
            {
               panel.Children.Add(view);
            }
         }
      }
   }
}